<template>
    <view class="content">
        <div class="lr-warp">
            <div class="lr-list">
                <div class="lr-item">
                    <image src="../../static/images/z_phone.png" class="icon"></image>
                    <input type="text" value="" v-model="submit_data.mobile" placeholder="请输入手机号" />
                </div>
                <div class="lr-item">
                    <image src="../../static/images/z_lock.png" class="icon"></image>
                    <input type="number" value="" v-model="submit_data.code" placeholder="请输入验证码" />
                    <a @tap="getCode" class="getCode">{{codeText}}</a>
                </div>
                <div class="lr-item">
                    <image src="../../static/images/z_lock.png" class="icon"></image>
                    <input type="password" value="" v-model="submit_data.pass" placeholder="请输入密码" />
                </div>
                <div class="lr-item">
                    <image src="../../static/images/z_lock.png" class="icon"></image>
                    <input type="password" value="" v-model="submit_data.pass1" placeholder="请确认密码" />
                </div>
            </div>
            <button class="lr-btn" @tap="submitData">确认</button>
        </div>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                codeText : '获取验证码',
                submit_data : {
                    mobile : '',
                    code : '',
                    pass : '',
                    pass1 : ''
                }
            }
        },
        methods: {
            //获取验证码
            getCode() {
            	let t = this;
            	if (!this.submit_data.mobile) {
            		this.util.uToast({
            			tit: '请输入手机号码'
            		});
            		return false;
            	}
            	if(t.codeText == '重新发送' || t.codeText == '获取验证码'){
            		let timeNumber = 60;
            		let timeInter = setInterval(() => {
            			timeNumber--;
            			if (timeNumber == 0) {
            				clearInterval(timeInter);
            				t.codeText = '重新发送';
            				return false;
            			}
            			t.codeText = timeNumber + "s后重新发送";
            		}, 1000);
            	}else{
            		return false;
            	}
            	let param = {};
            	param.is_loading = true;
            	param.url = "api/shop/login/send_check_num";
            	param.data = {};
            	param.data.shop_num = this.submit_data.mobile;
            	this.util.requests(param, res => {
            		this.util.uToast({
            			tit: '短信发送成功'
            		});
            	});
            },
            submitData() {
                let t = this;
                if (!this.submit_data.mobile) {
                	this.util.uToast({
                		tit: '请输入手机号码'
                	});
                	return false;
                }
                if (!this.submit_data.code) {
                	this.util.uToast({
                		tit: '请输入短信验证码'
                	});
                	return false;
                }
                if (!this.submit_data.pass) {
                	this.util.uToast({
                		tit: '请输入登录密码'
                	});
                	return false;
                }
                if (this.submit_data.pass != this.submit_data.pass1) {
                	this.util.uToast({
                		tit: '两次密码输入不一致'
                	});
                	return false;
                }
                let param = {};
                param.is_loading = true;
                param.url = "api/shop/login/savepass";
                param.data = {};
                param.data.shop_num = this.submit_data.mobile;
                param.data.number = this.submit_data.code;
                param.data.shop_pass = this.submit_data.password;
                this.util.requests(param, res => {
                    if(res.data.code == 1) {
                        uni.showModal({
                            title: '提示',
                            showCancel: false,
                            content: '密码找回成功',
                            success: function(res) {
                                if (res.confirm) {
                                    uni.navigateTo({
                                        url: '../login/index'
                                    })
                                }
                            }
                        })
                    }
                });
            }
        },
    }
</script>
<style>

    .content {
        padding-bottom: 1upx;
    }

    .logo {
        width: 91upx;
        height: 80upx;
        display: block;
        margin: 0 auto;
    }

    .lr-warp {
        padding:0 30upx;
        position: relative;
        z-index: 100;
    }

    .lr-list {
        margin: 100upx 0 180upx 0;
    }

    .lr-list .icon {
        width: 34upx;
        height: 34upx;
    }

    .lr-list .lr-item {
        padding: 20upx 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1upx solid #e6e6e6;
        margin-bottom: 60upx;
    }

    .lr-list .lr-item .getCode {
        color: #fc21fc;
        font-size: 28upx;
        padding: 10upx 15upx;
        border: 1upx solid #fc21fc;
        border-radius: 6upx;
    }

    .lr-list .lr-item input {
        flex: 1;
        font-size: 28upx;
        margin: 0 20upx 0 70upx;
    }

    .lr-btn {
        height: 70upx;
        line-height: 70upx;
        color: #fff;
        font-size: 32upx;
        text-align: center;
        border-radius: 100upx;
        background: #fb21fc;
    }

</style>
